using System;
using System.Collections.Generic;
using System.Drawing;
using OhioState.AssetManaged;

namespace OhioState.Graphics.Proxy
{
    /// <summary>
    /// Class for applying MotionBlur effect to a layer
    /// </summary>
    [Serializable()]
    public class MotionBlurredLayerProxy : SharedAsset, ILayer, IDrawable, System.ICloneable
    {
        private LayerProxy _layer;
        /// <summary>
        /// Get/set a layer
        /// </summary>
        public LayerProxy Layer
        {
            get { return _layer; }
            set { _layer = value; }
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="layer">Name of the layer</param>
        public MotionBlurredLayerProxy(LayerProxy layer)
            : base(layer.Name+"Blurred") 
         {
             _layer = layer;
             _layer.AddChangedEventHandler( new OhioState.AssetManaged.IAssetManagedHandler(layer_ChangedEvent));
         }
         /// <summary>
         /// Get the layer's width
         /// </summary>
         public int Width
         {
             get { return _layer.Width; }
         }

         /// <summary>
         /// Get the layer's height
         /// </summary>
         public int Height
         {
             get { return _layer.Height; }
         }

        /// <summary>
        /// Get/Set layer's image
        /// </summary>
        public Bitmap Image
        {
            get { return _layer.Image; }
            set { _layer.Image = value; }
        }

        private bool _paused = false;
        /// <summary>
        /// Get/Set Paused variable
        /// </summary>
        public bool Paused
        {
            get { return _paused; }
            set { _paused = value; }
        }

        /// <summary>
        /// Add a drawable to a layer
        /// </summary>
        /// <param name="drProxy">drawable</param>
        public void addDrawableProxy(IDrawable drProxy)
        {
            _layer.addDrawableProxy(drProxy);
        }

        /// <summary>
        /// Remove drawable from a layer
        /// </summary>
        /// <param name="drProxy">drawable</param>
        public void removeDrawableProxy(IDrawable drProxy)
        {
            _layer.removeDrawableProxy(drProxy);
        }
        /// <summary>
        /// Add event handler for material change
        /// </summary>
        /// <param name="e"> event handler</param>
        public void AddMaterialChangedEventHandler(IAssetManagedHandler e)
        {
            _layer.AddMaterialChangedEventHandler(e);
        }

        /// <summary>
        /// Remove event handler for material change
        /// </summary>
        /// <param name="e"></param>
        public void RemoveMaterialChangedEventHandler(IAssetManagedHandler e)
        {
            _layer.RemoveMaterialChangedEventHandler(e);
        }
        /// <summary>
        /// Fire event if the layer changes
        /// </summary>
        /// <param name="obj"></param>
        protected void layer_ChangedEvent(IAssetManaged obj)
        {
            FireUpdateChangedEvent(this);
        }

         #region ILayer Members
        /// <summary>
        /// Implementation of ILayer Material Get/Set Accessor
        /// </summary>
         public OhioState.Graphics.IMaterial Material
         {
             get
             {
                 return _layer.Material;
             }
             set
             {
                 _layer.Material = value;
             }
         }

        /// <summary>
        /// Implementation of ILayer Active Accessor that sets/ gets the active layers
        /// </summary>
         public bool Active
         {
             get
             {
                 return _layer.Active;
             }
             set
             {
                 _layer.Active = value;
             }
         }
        /// <summary>
        /// Implementation of ILayer Get/Set Accessor Camera, 
        /// </summary>
         public OhioState.Graphics.ICamera Camera
         {
             get
             {
                 return _layer.Camera;
             }
             set
             {
                 _layer.Camera = value;
             }
         }
            
        /// <summary>
        /// Get the list of all the drawables in this (motion blurred) layer
        /// </summary>
        public List<OhioState.Graphics.IDrawable> Drawables
        {
            get { return _layer.Drawables; }
        }

        public IFrameBufferObject FrameBuffer
        {
            get { return _layer.FrameBuffer; }
            set { _layer.FrameBuffer = value; }
        }

        /// <summary>
        /// Implementation of IDrawable method Render
        /// </summary>
        /// <param name="panel"></param>
        public void Render(IRenderPanel panel)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        #endregion

        #region IDrawable Members

        /// <summary>
        /// Implementation of IDrawable Accessor Bounding Volume
        /// </summary>

        public OhioState.Graphics.IBoundingVolume BoundingVolume
        {
            get { return _layer.BoundingVolume; }
        }

        /// <summary>
        /// Get/Set a drawable's position in this layer
        /// </summary>
        public int DrawablePosition
        {
         get
         {
             return _layer.DrawablePosition;
         }
         set
         {
             _layer.DrawablePosition = value;
         }
        }

        #endregion

        #region ICloneable Members
        /// <summary>
        /// Clone this object
        /// </summary>
        /// <returns>cloned object</returns>
        public object Clone()
        {
         return new MotionBlurredLayerProxy(_layer.Clone() as LayerProxy);
        }

        #endregion
     }
}
